package com.zoho.daliansheng.config;

import com.zoho.daliansheng.common.U8SystemRecord;
import org.springframework.stereotype.Component;

@Component
public class U8SystemPathConfig {

    U8SystemRecord u8SystemRecord;

    public U8SystemPathConfig(U8SystemRecord u8SystemRecord) {
        this.u8SystemRecord = u8SystemRecord;
    }

    private final String headPath = "https://api.yonyouup.com/";

    // 获取token
    String tokenPath = "system/token";

    // 获取交易号
    String tradeIdPath = "system/tradeid";

    // 批量获取存货信息
    String batchGetInventory = "system/tradeid";

    private String getParameter() {
        return "?from_account=" + u8SystemRecord.getFromAccount() + "&app_key=" + u8SystemRecord.getAppKey() + "&token=" + u8SystemRecord.getAccessToken();
    }

    private String getDataSource(String dataSource) {
        return "?from_account=" + u8SystemRecord.getFromAccount() + "&app_key=" + u8SystemRecord.getAppKey() + "&token=" + u8SystemRecord.getAccessToken() + "&ds_sequence=" + dataSource;
    }

    private String getAllDataSource(String dataSource) {
        return "?from_account=" + u8SystemRecord.getFromAccount() + "&to_account=" + u8SystemRecord.getToAccount() + "&app_key=" + u8SystemRecord.getAppKey() + "&token=" + u8SystemRecord.getAccessToken() + "&ds_sequence=" + dataSource;
    }

    public String getToken() {
        return headPath + tokenPath;
    }

    public String getTradeId() {
        return headPath + tradeIdPath + getParameter();
    }

    // 批量获取 存货信息
    public String getBatchInventory(String dataSource) {
        return headPath + "api/inventory/batch_get" + getAllDataSource(dataSource);
    }

    // 单条存货信息
    public String getInventory(String dataSource, String id) {
        return headPath + "api/inventory/get" + getAllDataSource(dataSource) + "&id=" + id;
    }

    // 新增客户
    public String getAddAccount(String dataSource, String tradeid) {
        return headPath + "api/customer/add" + getAllDataSource(dataSource) + "&tradeid=" + tradeid;
    }

    // 批量获取 仓库
    public String getBatchWarehouse(String dataSource) {
        return headPath + "api/warehouse/batch_get" + getAllDataSource(dataSource);
    }

    // 批量获取 销售出库单
    public String getBatchSaleoutlistall(String dataSource, String date) {
        return headPath + "api/saleoutlistall/batch_get" + getAllDataSource(dataSource) + "&date_begin=" + date;
    }

    // 批量获取 人员
    public String getBatchPerson(String dataSource) {
        return headPath + "api/person/batch_get" + getAllDataSource(dataSource);
    }

    // 批量获取 现存量
    public String getBatchCurrentstock(String dataSource) {
        return headPath + "api/currentstock/batch_get" + getAllDataSource(dataSource);
    }

    // 批量获取 收款单
    public String getBatchAcceptlist(String dataSource) {
        return headPath + "api/acceptlist/batch_get" + getAllDataSource(dataSource);
    }
}
